package com.cssw.fyzb.busi.api.acct;

import com.cssw.fyzb.core.exception.BizException;
import com.cssw.fyzb.busi.service.acct.OutAcctService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Function(description = "删除银行卡", parameters = {
        @Parameter(name = "userId", type = Type.String, description = "用户标识", required = true),
        @Parameter(name = "bankId", type = Type.String, description = "银行卡", required = true)
})
@Component
public class DeleteBankPay implements Action {

    private static Logger logger = LoggerFactory.getLogger(DeleteBankPay.class);


    @Autowired
    private OutAcctService outAcctService;

    @Override
    public Response execute(Request request) throws Exception {
        Long bankId = request.getLong("bankId");
        Long userId = request.getLong("userId");

        try {
            outAcctService.deleteBank(userId, bankId);
        }
        catch (BizException e){
            return Response.fail(e.getErrMsg(), e.getErrCode());
        }
        catch(Exception e){
            logger.error("", e);
            return Response.fail("删除银行卡信息失败");
        }
        return Response.success();


    }
}
